package com.dk.controller;

import com.dk.pojo.Emp;
import com.dk.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("emp")
public class EmpController {
    @Autowired才2222222222
    private EmpService es;

    @RequestMapping("getAll")
    @ResponseBody
    public List<Emp> getEmp(){
        return es.getEmp();
    }

    @RequestMapping("addSkip")
    public String addSkip(){
        return "emp/addEmp";
    }

    @RequestMapping("addEmp")
    @ResponseBody
    public int addEmp(Emp e){
        return es.addEmp(e);
    }

    @RequestMapping("deleteEmp")
    @ResponseBody
    public int deleteEmp(Integer id){
        return es.deleteEmp(id);
    }

    @RequestMapping("getById")
    public String getById(Integer id, Model m){
        m.addAttribute("e",es.getById(id));
        return "emp/updateEmp";
    }

    @RequestMapping("updateEmp")
    @ResponseBody
    public int updateEmp(Emp e){
        return es.updateEmp(e);
    }

}
